<?php
	
	include 'modules/cart.php';
	$cart = new cartWrapper();
	
	include 'modules/navigation.php';	
	$navigation = new navigationWrapper();
	
	if (isset($_GET['cid'])) {
		$page_id = $_GET['cid'];
	} else {
  		$page_id = "";
	}
	
	$smarty->assign('page_id', $page_id);
	$smarty->assign('menu', $navigation->getMenu());

	if(getOption('cb-global-sitedocs',1) == 1){
  		$smarty->assign('menuArray',$navigation->getMenuArray(1));	
	} else {
  		$smarty->assign('menuArray',$navigation->getMenuArray($config['id']));
	}

	if (isset($content)) {
		$smarty->assign('page_content',$content);
	}

	$smarty->assign('categories',$cart->getCartCategoriesNames());
	$smarty->assign('fullmenu',$cart->getMenuList());
	$smarty->assign('allmenus',$cart->getMenus());
	$smarty->assign('title',$config['title']);
	$smarty->assign('title',$config['description']);
	$smarty->assign('title',$config['keywords']);
	$smarty->assign('allmenus',$cart->getMenus());

	$topfour = $database->select("SELECT * from menu_item  WHERE rid = ".RID." order by id desc limit 4");
	
	for ($h=0; $h<count($topfour); $h++){ 
		$topfour[$h]['prices'] = unserialize($topfour[$h]['price']);
		$topfour[$h]['optionsun'] = unserialize($topfour[$h]['options']);
	
		if($topfour[$h]['image'] == ""){
			$image = 'images/no_image.gif';
		} else {
			$image = 'UserFiles/Image/product_photos/'.$topfour[$h]['image'].'';
		}
	}
	
	$latest_news = $database->select("SELECT * from news where rid = ".RID." order by RAND() LIMIT 3");
	$smarty->assign('latest_news',$latest_news);
	$smarty->assign('topfour',$topfour);
	$smarty->assign('config',getConfig());
	
	if(isset($_SESSION['userid']) && $_SESSION['userid'] != ''){
  		$smarty->assign('user',userArray($_SESSION['userid']));
	}
	
	function get_price_format_js(){
  		global $database;
		$id = RID;
  		$config = $database->select('SELECT * FROM config where id = ' . $id . '');
	  	$symbol = $config[0]['money_symbol'];
  		$format = "var priceFormat = '$symbol{amount}';";

  		if ($config[0]['money_position'] != 1) {
    		$format = "var priceFormat = '{amount}$symbol';"; 
  		}
  
  		return "function price_format(amount){ $format return priceFormat.replace('{amount}', parseFloat(amount).toFixed(2)); }";
	}

	if (!isset($javascript) ) {
  		$javascript = "";
	}

	$javascript .= get_price_format_js();
	
	$datos = $database->select("SELECT * from locations  WHERE rid = ".RID." ");
	
	$smarty->assign('javascript',$javascript);	
	$smarty->assign('search_categories',getOption('category',NULL,FALSE,TRUE));
	$smarty->assign('search_areas',getOption('area'));
	$smarty->assign('cat_list_view',getOption('cb-show-cat-list'), RID);
	$smarty->assign('datos', $datos);
?>